<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############


$THEME->addBreadcrumb($this->adminUrl, $this->lang('breadcrumb_upload'));

$folderPath = $this->getFolderPath('def');


if(Antz_IntelliForm::submitted('upload-files')){

	$error = false;
	$parent = preg_replace('/[^a-zA-Z0-9]/', '', post('parent'));

	if($DB->countRows($CONFIG->dbprefix.$this->keyname.'_folders', "id = '{$parent}'")==0){
		$error = true;
		JFX::addError($this->lang('upload_invalid_parent'));
	}

	if(!$error){
		$folderPath = $this->getFolderPath($parent);
		for($i=0; $i<10; $i++){
			if(array_key_exists('file'.$i, $_FILES)){
				// the file exists
				$fData = $_FILES['file'.$i];
				if(!file_exists($fData['tmp_name'])){
					continue;
				}
				$file = JFX_Data::newFile($this->keyname, $fData['tmp_name'], $fData['name'], $folderPath);
				$file->save();
				JFX::addSuccess('Uploaded ok!');
			}
		}
		JFX::redirect($this->adminUrl);
	}



}




$formField = array(
	'type' => 'file',
	'name' => 'file',
	'value' => ''
);

$parentOpts = array();
$this->makeFolderDropMenu($parentOpts, '', 0, post('parent', 'root'));

$formFields = array(
	array(
		'type' => 'select',
		'name' => 'parent',
		'label' => $this->lang('upload_parent'),
		'options' => $parentOpts,
		'value' => post('parent')
	)
);
for($i=0; $i<10; $i++){
	$formField['name'] = 'file'.$i;
	$formFields[] = $formField;
}

$formFields[] = array(
	'type' => 'submit',
	'name' => 'submitBtn',
	'value' => $this->lang('upload_submit'),
	'label' => '&nbsp;'
);

echo JFX::makeRapidForm($formFields, $this->lang('form_upload_legend'), 'upload-files');